package own.stu.jobgib.playown.redis.redisson;

import lombok.AllArgsConstructor;
import lombok.Data;
import org.redisson.api.RBucket;
import org.redisson.api.RBuckets;
import org.redisson.api.RedissonClient;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class BucketTest extends BaseTest {

    public static void main(String[] args) {
        RedissonClient client = getClient();

        RBucket<TV> bucket = client.getBucket("on");
        TV tv = new TV("lo", new Date());
        bucket.set(tv);

        System.out.println(bucket.get());

        System.out.println(bucket.setIfAbsent(tv));

        TV l1 = new TV("l1", new Date());
        TV l2 = new TV("l2", new Date());
        TV l3 = new TV("l3", new Date());
        Map<String, TV> map = new HashMap<>();
        map.put(l1.getName(), l1);
        map.put(l2.getName(), l2);
        map.put(l3.getName(), l3);

        RBuckets buckets = client.getBuckets();
        buckets.set(map);

        Map<String, Object> stringObjectMap = buckets.get("l1", "l2");
        System.out.println(stringObjectMap);

        close();
    }

    @AllArgsConstructor
    @Data
    public static class TV {
        String name;
        Date date;
    }
}
